package com.zgr.ssm.service.impl;

import com.zgr.ssm.entity.FileEntity;
import com.zgr.ssm.mapper.FileMapper;
import com.zgr.ssm.service.IFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FileServiceImpl implements IFileService {

    @Autowired
    private FileMapper fileMapper;

    @Override
    public void upload(FileEntity file) {
        fileMapper.insert(file);
    }

    @Override
    public List<FileEntity> getList(Integer uid) {
        List<FileEntity> list = findByUid(uid);
        return list;
    }

    private Integer insert(FileEntity file){
        Integer rows = fileMapper.insert(file);
        if(rows == 1){
            return rows;
        }else{
            throw new RuntimeException("上传失败！请联系管理员");
        }
    }

    private List<FileEntity> findByUid(Integer uid){
        return fileMapper.findByUid(uid);
    }
}
